package P1000;

import java.util.Scanner;

/**
 * @author: zhouyang
 * @descrpition: 从A走到B 走2次 能拿的最高分 动态规划
 * @time: 2019-09-29 18:15
 */
public class P1004_方格取数 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[][] map = new int[N][N];
        while(true){
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int score = scanner.nextInt();
            if((x+y+score) == 0){
                scanner.close();
                invoke(map);
                return ;
            }
            map[x-1][y-1] = score;
        }
    }

    private static void invoke(int[][] map) {
        int N = map.length;
        int[][][][] dp = new int[N+1][N+1][N+1][N+1];
        for(int i=1;i<=N;++i){
            for(int j=1;j<=N;++j){
                for(int p=1;p<=N;++p){
                   int q = i+j-p;
                   if(q <= 0 || q > N) continue;
                   dp[i][j][p][q] = Math.max(Math.max(dp[i-1][j][p-1][q],dp[i-1][j][p][q-1])
                           ,Math.max(dp[i][j-1][p-1][q],dp[i][j-1][p][q-1]));
                   if(i==p && j==q){
                       dp[i][j][p][q] += map[i-1][j-1];
                   }else{
                       dp[i][j][p][q] += (map[i-1][j-1]+map[p-1][q-1]);
                   }
                }
            }
        }
        System.out.println(dp[N][N][N][N]);
    }
}
